<template>
	<view class="content pageBg">
		<custom-nav-bar #title>推荐</custom-nav-bar>
		<view class="banner">
			<swiper indicator-dots="true" autoplay="true" circular="true">
				<swiper-item v-for="item in bannerList" :key="item._id">
					<image :src="item.picurl" mode=""></image>
				</swiper-item>
			</swiper>
		</view>
		<view class="notice">
			<uview class="left">
				<uni-icons type="sound-filled" size="20" color="#23b389"></uni-icons>
				<text class="text">公告</text>
			</uview>
			<uview class="center">
				<swiper interval="1500" autoplay="true" circular="true" vertical>
					<swiper-item v-for="item in 3" :key="item">
						<navigator url="/pages/notice/detail">
							公告内容
						</navigator>
					</swiper-item>
				</swiper>
			</uview>
			<uview class="right">
				<uni-icons type="right" size="20" color="#797674"></uni-icons>
			</uview>
		</view>

		<view class="select">
			<!-- 引入公共标题组件 -->
			<common-title>
				<template #name>每日推荐</template>
				<template #custom>
					<view class="date">
						<uni-icons type="calendar" size="18" color="#23b389"></uni-icons>
						<view class="text">
							<uni-dateformat :date="Date.now()" :format="'yyyy-MM-dd'"></uni-dateformat> <!-- 格式化时间 -->
						</view>
					</view>
				</template>
			</common-title>

			<view class="wallpaper">
				<scroll-view scroll-x :show-scrollbar="false">
					<view class="box" v-for="(item, index) in DayRandomList" :key="item._id"
						@click="goPreview(item._id)">
						<image :src="item.smallPicurl" mode="aspectFill"></image>
					</view>
				</scroll-view>
			</view>
		</view>


		<view class="theme">
			<!-- 引入公共标题组件 -->
			<common-title>
				<template #name>专题精选</template>
				<template #custom>
					<view class="more" @click="goClassify">
						<uni-icons type="more" size="30"></uni-icons>
					</view>
				</template>
			</common-title>


			<view class="theme-wallpaper">
				<theme-item v-for="item in classifyList" :key="item._id" :item="item"></theme-item>
				<theme-item :isMore="true"></theme-item>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		globalVariable
	} from '../All.js'; // 请求重复的变量
	var bannerList = ref([]); // 接收首页海报返回的数组
	var DayRandomList = ref([]); // 接收每日推荐返回的数组
	var classifyList = ref([]); // 接收壁纸分类
	var noticeList = ref([]); // 接收公告列表


	// 首页海报
	var getBanner = async () => {
		var res = await uni.request({
			url: globalVariable().url + 'homeBanner',
			header: {
				"access-key": globalVariable().accessKey
			}
		})
		// console.log(res);
		if (res.data.errCode === 0) {
			// 查询成功
			bannerList.value = res.data.data;
		}
	}

	// 每日推荐
	var getDayRandom = async () => {
		var res = await uni.request({
			url: globalVariable().url + 'randomWall',
			header: {
				"access-key": globalVariable().accessKey
			}
		})
		// console.log(res);
		if (res.data.errCode === 0) {
			// 查询成功
			DayRandomList.value = res.data.data;
		}
	}

	// 壁纸分类
	var classIfication = async () => {
		var res = await uni.request({
			url: globalVariable().url + 'classify',
			header: {
				"access-key": globalVariable().accessKey
			},
			data: {
				select: true
			}
		})
		// console.log(res);
		if (res.data.errCode === 0) {
			// 查询成功
			classifyList.value = res.data.data;
		}
	}
	// 公告
	var getNotice = async () => {
		var res = await uni.request({
			url: globalVariable().url + 'wallNewsList',
			header: {
				"access-key": globalVariable().accessKey
			}
		})
		// console.log(res);
		if (res.data.errCode === 0) {
			// 查询成功
			noticeList.value = res.data.data;
		}
	}


	getBanner();
	getDayRandom();
	classIfication();
	getNotice();



	// 跳转
	var goPreview = (e) => {
		uni.navigateTo({
			url: '../preview/preview?id=' + e
		})
	};
	var goClassify = () => {
		uni.switchTab({
			url: '/pages/classify/classify'
		})
	};
</script>

<style lang="scss" scoped>
	.content {
		.banner {
			width: 750rpx;
			// height: 300rpx;
			padding: 30rpx 0;

			swiper {
				height: 340rpx;
				width: 100%;

				&-item {
					width: 100%;
					height: 100%;
					padding: 0 30rpx;

					image {
						width: 100%;
						height: 100%;
						border-radius: 20rpx;
					}
				}
			}
		}

		.notice {
			width: 690rpx;
			height: 80rpx;
			line-height: 80rpx;
			// padding: 30rpx 0;
			background: #e6e6e6;
			margin: 0 auto;
			border-radius: 80rpx;
			display: flex;

			.left {
				width: 140rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				.text {
					color: #23b389;
					font-size: 30rpx;
					font-weight: 600;
				}


			}

			.center {
				flex: 1;

				swiper {
					height: 100%;

					&-item {
						height: 100%;
						font-size: 30rpx;
						color: #666;
						overflow: hidden;
						white-space: nowrap; // 不换行
						text-overflow: ellipsis; // 文本溢出
					}
				}
			}

			.right {
				width: 70rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}


		.select {
			padding-top: 50rpx;

			.date {
				color: #23b389;
				display: flex;
				align-items: center;

				.text {
					margin-left: 5rpx;
				}
			}

			.wallpaper {
				width: 720rpx;
				margin-left: 30rpx;
				margin-top: 30rpx;

				scroll-view {
					white-space: nowrap; // 不换行

					.box {
						width: 200rpx;
						height: 430rpx;
						display: inline-block;
						margin-right: 15rpx;

						image {
							height: 100%;
							width: 100%;
							border-radius: 20rpx;
						}
					}

					.box:last-child {
						margin-right: 30rpx;
					}
				}
			}
		}

		.theme {
			padding: 50rpx 0;

			.theme-wallpaper {
				margin-top: 30rpx;
				padding: 0 30rpx;
				display: grid;
				gap: 15rpx;
				grid-template-columns: repeat(3, 1fr); // 一行显示三个
			}
		}
	}
</style>